package cz.possoft.client.clovece.gui.components;

import java.util.HashMap;
import java.util.Map;

import cz.possoft.serializable.clovece.game.CloveceField;
import cz.possoft.serializable.generic.Location;

/**
 * @author <a href="mailto:mposolda@gmail.com">Marek Posolda</a>
 */
public class CloveceFigurkaOnPane
{
   public static final Map<Integer, Location> BASIC_FIELD_LOCATIONS = new HashMap<Integer, Location>();
   
   public static final Map<Integer, Location> WHITE_PLAYER_HOME_FIELD_LOCATIONS = new HashMap<Integer, Location>();
   public static final Map<Integer, Location> BLACK_PLAYER_HOME_FIELD_LOCATIONS = new HashMap<Integer, Location>();
   
   public static final Map<Integer, Location> WHITE_PLAYER_START_FIELD_LOCATIONS = new HashMap<Integer, Location>();
   public static final Map<Integer, Location> BLACK_PLAYER_START_FIELD_LOCATIONS = new HashMap<Integer, Location>();   
   
   static
   {
      BASIC_FIELD_LOCATIONS.put(0, new Location(4, 10));
      BASIC_FIELD_LOCATIONS.put(1, new Location(5, 10));
      BASIC_FIELD_LOCATIONS.put(2, new Location(6, 10));
      BASIC_FIELD_LOCATIONS.put(3, new Location(6, 9));
      BASIC_FIELD_LOCATIONS.put(4, new Location(6, 8));
      BASIC_FIELD_LOCATIONS.put(5, new Location(6, 7));
      BASIC_FIELD_LOCATIONS.put(6, new Location(6, 6));
      BASIC_FIELD_LOCATIONS.put(7, new Location(7, 6));
      BASIC_FIELD_LOCATIONS.put(8, new Location(8, 6));
      BASIC_FIELD_LOCATIONS.put(9, new Location(9, 6));
      
      BASIC_FIELD_LOCATIONS.put(10, new Location(10, 6));
      BASIC_FIELD_LOCATIONS.put(11, new Location(10, 5));
      BASIC_FIELD_LOCATIONS.put(12, new Location(10, 4));
      BASIC_FIELD_LOCATIONS.put(13, new Location(9, 4));
      BASIC_FIELD_LOCATIONS.put(14, new Location(8, 4));
      BASIC_FIELD_LOCATIONS.put(15, new Location(7, 4));
      BASIC_FIELD_LOCATIONS.put(16, new Location(6, 4));
      BASIC_FIELD_LOCATIONS.put(17, new Location(6, 3));
      BASIC_FIELD_LOCATIONS.put(18, new Location(6, 2));
      BASIC_FIELD_LOCATIONS.put(19, new Location(6, 1));    
      
      BASIC_FIELD_LOCATIONS.put(20, new Location(6, 0));
      BASIC_FIELD_LOCATIONS.put(21, new Location(5, 0));
      BASIC_FIELD_LOCATIONS.put(22, new Location(4, 0));
      BASIC_FIELD_LOCATIONS.put(23, new Location(4, 1));
      BASIC_FIELD_LOCATIONS.put(24, new Location(4, 2));
      BASIC_FIELD_LOCATIONS.put(25, new Location(4, 3));
      BASIC_FIELD_LOCATIONS.put(26, new Location(4, 4));
      BASIC_FIELD_LOCATIONS.put(27, new Location(3, 4));
      BASIC_FIELD_LOCATIONS.put(28, new Location(2, 4));
      BASIC_FIELD_LOCATIONS.put(29, new Location(1, 4));  
      
      BASIC_FIELD_LOCATIONS.put(30, new Location(0, 4));
      BASIC_FIELD_LOCATIONS.put(31, new Location(0, 5));
      BASIC_FIELD_LOCATIONS.put(32, new Location(0, 6));
      BASIC_FIELD_LOCATIONS.put(33, new Location(1, 6));
      BASIC_FIELD_LOCATIONS.put(34, new Location(2, 6));
      BASIC_FIELD_LOCATIONS.put(35, new Location(3, 6));
      BASIC_FIELD_LOCATIONS.put(36, new Location(4, 6));
      BASIC_FIELD_LOCATIONS.put(37, new Location(4, 7));
      BASIC_FIELD_LOCATIONS.put(38, new Location(4, 8));
      BASIC_FIELD_LOCATIONS.put(39, new Location(4, 9));  
      
      WHITE_PLAYER_HOME_FIELD_LOCATIONS.put(0, new Location(5, 9));
      WHITE_PLAYER_HOME_FIELD_LOCATIONS.put(1, new Location(5, 8));
      WHITE_PLAYER_HOME_FIELD_LOCATIONS.put(2, new Location(5, 7));
      WHITE_PLAYER_HOME_FIELD_LOCATIONS.put(3, new Location(5, 6));
      
      BLACK_PLAYER_HOME_FIELD_LOCATIONS.put(0, new Location(5, 1));
      BLACK_PLAYER_HOME_FIELD_LOCATIONS.put(1, new Location(5, 2));
      BLACK_PLAYER_HOME_FIELD_LOCATIONS.put(2, new Location(5, 3));
      BLACK_PLAYER_HOME_FIELD_LOCATIONS.put(3, new Location(5, 4));    
      
      WHITE_PLAYER_START_FIELD_LOCATIONS.put(0, new Location(0, 9));
      WHITE_PLAYER_START_FIELD_LOCATIONS.put(1, new Location(0, 10));
      WHITE_PLAYER_START_FIELD_LOCATIONS.put(2, new Location(1, 9));
      WHITE_PLAYER_START_FIELD_LOCATIONS.put(3, new Location(1, 10));
      
      BLACK_PLAYER_START_FIELD_LOCATIONS.put(0, new Location(9, 0));
      BLACK_PLAYER_START_FIELD_LOCATIONS.put(1, new Location(9, 1));
      BLACK_PLAYER_START_FIELD_LOCATIONS.put(2, new Location(10, 0));
      BLACK_PLAYER_START_FIELD_LOCATIONS.put(3, new Location(10, 1));       
   }
   
   private final CloveceField field;
   private final Location location;
   private int ringColor;    
   private int ringSelectedForPlay;
   private int ringForPlaceWhereWeCanPlay;
   
   // we need to have reference of neighbour here as well.
   private CloveceFigurkaOnPane neighbourFrom;
   
   public CloveceFigurkaOnPane(CloveceField field, Location location)
   {
      if ((field == null) || (location == null))
      {
         throw new IllegalArgumentException("Field can't be null and is " + field + ". Location can't be null and is " + location);
      }
      this.field = field;
      this.location = location;   
      this.ringColor = 0;
      this.ringSelectedForPlay = 0;
      this.ringForPlaceWhereWeCanPlay = 0;
   }

   public CloveceField getField()
   {
      return field;
   }

   public Location getLocation()
   {
      return location;
   }

   public CloveceFigurkaOnPane getNeighbourFrom()
   {
      return neighbourFrom;
   }

   public void setNeighbourFrom(CloveceFigurkaOnPane neighbourFrom)
   {
      this.neighbourFrom = neighbourFrom;
   }

   public int getRingColor()
   {
      return ringColor;
   }

   public void setRingColor(int ringColor)
   {
      this.ringColor = ringColor;
   }

   public int getRingSelectedForPlay()
   {
      return ringSelectedForPlay;
   }

   public void setRingSelectedForPlay(int ringSelectedForPlay)
   {
      this.ringSelectedForPlay = ringSelectedForPlay;
   }       
   
   public int getRingForPlaceWhereWeCanPlay()
   {
      return ringForPlaceWhereWeCanPlay;
   }

   public void setRingForPlaceWhereWeCanPlay(int ringForPlaceWhereWeCanPlay)
   {
      this.ringForPlaceWhereWeCanPlay = ringForPlaceWhereWeCanPlay;
   }

   public String toString()
   {
      return new StringBuilder("CloveceFigurkaOnPane [field=").append(field).append(", location=").
                 append(location).append(", ringColor=").append(ringColor).append(", ringSelectedForPlay=").append(ringSelectedForPlay).toString();
   }
   
   @Override
   public boolean equals(Object o)
   {
      if (!(o instanceof CloveceFigurkaOnPane))
      {
         return false;
      }
      CloveceFigurkaOnPane that = (CloveceFigurkaOnPane)o;
      return field.equals(that.field);
   }
   
   @Override
   public int hashCode()
   {
      return field.hashCode();
   }

}

